package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.dto.MaterialHalfDto;
import com.sale.system.domain.vo.MaterialHalfVo;
import com.sale.system.service.IMaterialHalfService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 半成品控制层
 * @Param
 * @Date 22-11-25
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/half")
public class MaterialHalfController extends BaseController {

    private final IMaterialHalfService materialHalfService;


    /**
     * 获取半成品配置
     */
    @SaCheckPermission("material:partially:list")
    @GetMapping("/list")
    public TableDataInfo<MaterialHalfDto> list(MaterialHalfVo materialHalfVo, PageQuery pageQuery)
    {
        return materialHalfService.selectHalfList(materialHalfVo,pageQuery);
    }

    /**
     * 新增半成品信息
     */
    @SaCheckPermission("material:partially:add")
    @Log(title = "半成品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody MaterialHalfVo materialHalfVo) throws Exception {
        return toAjax(materialHalfService.insertMaterialHalf(materialHalfVo));
    }

    /**
     * 删除半成品信息
     */
    @SaCheckPermission("material:partially:remove")
    @Log(title = "半成品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{materialId}")
    public R<Void> remove(@PathVariable("materialId") String materialId) throws Exception {
        return toAjax(materialHalfService.deleteMaterialHalf(materialId));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{materialId}")
    public R getHalfInfo(@PathVariable long materialId)
    {
        return R.ok(materialHalfService.selectMaterialHalfById(materialId));
    }

    /**
     * 修改半成品信息
     */
    @SaCheckPermission("material:partially:edit")
    @Log(title = "半成品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody MaterialHalfVo materialHalfVo) throws Exception {
        return toAjax(materialHalfService.updateMaterialHalfEdit(materialHalfVo));
    }


    /**
     * 半成品冻结
     */
    @Log(title = "成品信息", businessType = BusinessType.UPDATE)
    @PutMapping("/editFreeze/{materialId}")
    public R editFreeze(@PathVariable Long materialId) {
        return R.ok(materialHalfService.updateEditFreeze(materialId));
    }

    /**
     * 半成品解冻
     */
    @PutMapping("/editThaw/{materialId}")
    public R editThaw(@PathVariable Long materialId) {
        return R.ok(materialHalfService.updateEditThaw(materialId));
    }


    /**
     * 半成品信息导入
     */
/*    @PostMapping("/awmateriaImport")
    @RequiresPermissions("material:partially:import")
    @Log(title = "半成品信息导入", businessType = BusinessType.INSERT)
    public AjaxResult mouldMessageImport(MultipartFile file) throws Exception {
        ExcelUtil<MaterialHalfExport> excelUtil = new ExcelUtil<MaterialHalfExport>(MaterialHalfExport.class);
        List<MaterialHalfExport> coCustomer = excelUtil.importExcel(file.getInputStream());
        return AjaxResult.success(materiaHalfService.importMouldData(coCustomer));
    }*/

}
